import mongoose from 'mongoose';
import { ApiProperty } from '@nestjs/swagger';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import { User } from './user.schema';
import { Book } from './book.schema';
import { Order } from './order.schema';

@Schema({
  timestamps: true,
})
export class Car extends Document {
  @ApiProperty({ description: '用户ID', example: 'xxxx' })
  @Prop({ required: true, ref: 'User', type: mongoose.Schema.Types.ObjectId })
  user: User;

  @ApiProperty({ description: '图书ID', example: '图书ID' })
  @Prop({ required: true, ref: 'Book', type: mongoose.Schema.Types.ObjectId })
  book: Book;

  @ApiProperty({ description: '数量', example: 1 })
  @Prop({ required: true })
  number: number;

  @ApiProperty({ description: '订单ID', example: 'xxxx' })
  @Prop({ required: true, ref: 'Order', type: mongoose.Schema.Types.ObjectId })
  order: Order;
}

export type CarDocument = Car & Document;

export const CarSchema = SchemaFactory.createForClass(Car);
